﻿using Amazon.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AWS_FTP.Utilities;
using Amazon.SecurityToken;

namespace AWS_FTP
{
    /// <summary>
    /// Interaction logic for Authentication.xaml
    /// </summary>
    public partial class Authentication : Page
    {
        public Authentication()
        {
            InitializeComponent();
        }

        private void btnSignin_Click(object sender, RoutedEventArgs e)
        {
            try
            {
#if DEBUG       
                AmazonSecurityTokenService token_service = new AmazonSecurityTokenServiceClient("AKIAJYO4SCKGVCFCEUYQ","ECOox91XbC7BszoKZ46U8lxYnjuVpyxo6nz+HTbo",Amazon.RegionEndpoint.USWest2);
#else
                AmazonSecurityTokenService token_service = new AmazonSecurityTokenServiceClient(txtAccessKey.Text.Trim(), txtSecretKey.Text.Trim(), Guid.NewGuid().ToString());
#endif
                RefreshingSessionAWSCredentials refresh_aws_credentials = new RefreshingSessionAWSCredentials(token_service);
                Application.Current.Resources.Add(ResourceKeys.AUTH, refresh_aws_credentials);
                NavigationService.Navigate(new FileExplorer());
            }
            catch (Exception ex)
            {
                AWSLogger.Write("Authentication Failed.", ex as Exception);
            }
        }
    }
}